<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src=".././static/js/public-head.js"></script>
</head>
<body>

<div class="layui-row">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">输入关键字</label>
                        <div class="layui-input-inline">
                            <input  type="text"  name="keyword" placeholder="输入关键字" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <!--
                   <div class="layui-inline">
                       <label class="layui-form-label">输入关键字</label>
                       <div class="layui-input-inline">
                           <input  type="text"  name="keyword" placeholder="输入关键字" autocomplete="off" class="layui-input">
                       </div>
                   </div>
                   -->
                </div>
                <table class="layui-hide" id="sysParams-table" lay-filter="sysParams-table"></table>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    var layindex,layevent;
    layui.config({
        base: basePath+'/layui/lay/modules/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use([ 'table','form','formSelects' ], function() {
        var $ = layui.$;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var layer = layui.layer;
        var table = layui.table;

        var layindex;
        var exportData = []
        var tableOption = {
            elem: '#sysParams-table'
            ,url: basePath + '/sysParams/index'
            ,where:{token:token,keyword:function(){return $("input[name='keyword']").val()}}
            ,method:"post"
            ,toolbar:commonUtil.toolbarHTML()
            ,title:"系统参数配置"
            ,defaultToolbar:['filter', 'print']
            ,cols: [[
                {title: '请选择', width:80,type:"radio",fixed:'left'}
                ,{field:'PARAMS_TYPE', title: '参数类型',fixed:'left',sort:true }
                ,{field:'LABEL', title: '标签', sort:true,minWidth:100    }
                ,{field:'VALUE', title: '值',minWidth:100   }
                ,{field:'ORDER_NUM', title: '顺序'  }
                ,{field:'STATE', title: '状态',templet: function (d) {
                    return d.STATE != "1" ? "失效":"有效"
                } }
                ,{field:'PARAMS_DESC', title: '备注' }
                ,{field:'DATE_CREATED', title: '新增时间',hide:true  }
                ,{field:'LAST_UPDATED', title: '更新时间',hide:true }
                ,{field:'CREATOR', title: '创建人',hide:true }
                ,{field:'UPDATER', title: '更新人',hide:true }
            ]] ,
            exportHead:{PARAMS_TYPE: '参数类型',
                LABEL: '标签',
                VALUE: '值',
                STATE: '状态' ,
                ORDER_NUM: '顺序',
                PARAMS_DESC: '备注',
                UPDATER: '更新人',
                CREATOR: '创建人'}
            ,page: true
            ,height: 'full-100'
            ,done:function(res, curr, count){
                exportData = res.data;
            }
        }

        var tableDom = table.render(tableOption);
        var objId ;
        table.on("toolbar(sysParams-table)",function(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var titleLabel = ""
            if("delete-edit-detail-copy".indexOf(obj.event)!=-1 && checkStatus.data.length ==0){
                layer.msg("请选中后再操作")
                return
            }
            if( checkStatus.data.length !=0){
                objId =  checkStatus.data[0].ID || "";
                $("#objId").val(objId);
            }else{
                objId =  "";
                $("#objId").val("");
            }
            switch(obj.event){
                case 'del':
                    layer.confirm('确定删除该记录吗，该操作无法回退！', {icon: 3, title:'提示'}, function(index){
                        $.getJSON(basePath+"/sysParams/del",{token:token,ID:objId},function(rst){
                            layer.msg(rst.msg)
                            if(rst.code == 0){
                                table.reload("sysParams-table")
                            }
                        })
                        layer.close(index);
                    });

                    break;
                case "copy":
                    titleLabel = "新增参数"
                    layindex =   layer.open({
                        type:1,
                        title:"<ii class='layui-icon layui-icon-note'> "+titleLabel+"</ii>",
                        content: $("#sysParams-add-dom").html(),
                        area: ['700px', '500px'],
                        end : function(){
                            table.reload("sysParams-table")
                        },
                        success :function(layero, index){
                            formSelects.render("STATE")
                            $("input[name='PARAMS_TYPE']").attr("readOnly","readOnly")
                            $.getJSON(basePath+"/sysParams/getOne",{token:token,id:objId},function(rst){
                                if(rst.code ==0){
                                    //console.log(rst.data)
                                    var dataParam = rst.data[0]
                                    dataParam.ID = ""
                                    form.val("sysParams-form",dataParam)
                                    formSelects.value("STATE",[rst.data[0].STATE], true)
                                }
                            })
                        }
                    })
                    break;
                case 'edit':
                    titleLabel = "编辑参数"
                    layindex =   layer.open({
                        type:1,
                        title:"<ii class='layui-icon layui-icon-note'> "+titleLabel+"</ii>",
                        content: $("#sysParams-add-dom").html(),
                        area: ['700px', '500px'],
                        end : function(){
                            table.reload("sysParams-table")
                        },
                        success :function(layero, index){
                            formSelects.render("STATE")
                            $("input[name='PARAMS_TYPE']").attr("readOnly","readOnly")
                            $.getJSON(basePath+"/sysParams/getOne",{token:token,id:objId},function(rst){
                                if(rst.code ==0){
                                    //console.log(rst.data)
                                    form.val("sysParams-form",rst.data[0])
                                    formSelects.value("STATE",[rst.data[0].STATE], true)
                                }

                            })
                        }
                    })
                    break;
                case 'detail':break;
                case 'downLoad':
                    JSONToExcelConvertor(exportData,tableOption.title,tableOption.exportHead)
                    break;
                case 'add':
                    titleLabel = "新增参数"
                    layindex =   layer.open({
                        type:1,
                        title:"<ii class='layui-icon layui-icon-note'> "+titleLabel+"</ii>",
                        content: $("#sysParams-add-dom").html(),
                        area: ['700px', '500px'],
                        end : function(){
                            table.reload("sysParams-table")
                        },
                        success :function(layero, index){
                            formSelects.render("STATE")
                        }
                    })
                    break;
                case 'index':break;
                case 'save':break;
                case 'update':break;
                case 'upLoad':break;
                case 'query':
                    table.reload("sysParams-table")
                    break;
            }
        })

        form.on("submit(sysParams-form-bt)",function(obj){
            var objId = $("#objId").val()
            var url = basePath+"/sysParams/"
            var flag = "update"
            if(objId == null || objId == ""){
                flag = "add"
            }
            $.post(url+flag,commonUtil.getFormValueNormal(),function(rst){
                if(rst.code == 0){
                    layer.close(layindex)
                }
                layer.msg(rst.msg)
            },"json")
            return false
        })

    });

</script>
</body>

<script type="text/html" id="sysParams-add-dom">
    <div class="layui-card"  >
        <div class="layui-card-body"  >
            <form class="layui-form layui-form-pane" action="" lay-filter="sysParams-form">
                <input type="hidden" name="ID" value="" id="objId">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">参数类型</label>
                        <div class="layui-input-inline">
                            <input type="text" name="PARAMS_TYPE"  lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">标签</label>
                        <div class="layui-input-inline">
                            <input type="text" name="LABEL" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">值</label>
                        <div class="layui-input-inline">
                            <input type="text" name="VALUE"   lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">顺序</label>
                        <div class="layui-input-inline">
                            <input type="text" name="ORDER_NUM" lay-verify="number" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-inline">
                            <select  name="STATE" lay-verify="required" xm-select="STATE" xm-select-radio="">
                                <option value="">请选择</option>
                                <option value="1">有效</option>
                                <option value="0">失效</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item ">

                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-inline" style="width: 65%">
                        <textarea type="text" name="PARAMS_DESC"  lay-verify="required" autocomplete="off" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit="" lay-filter="sysParams-form-bt">保存</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</script>
</html>